package StudyCode.summary.mycollection;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class ChecksToSeeIfAnArrayContainsAnItem {
	public static void main(String[] argv) {
		Object[] arr = new String[]{"1", "abc", "level", null,
				"www.tah1986.com", "asdf 123"};
		Object item = "www.tah1986.com";
		System.out.println("数组是否包含 www.tah1986.com ？" + contains(arr, item));
	}

	public static boolean contains(Object[] arr, Object item) {
		if (arr == null)
			return false;

		for (int i = 0; i < arr.length; ++i) {
			if (item == null && arr[i] == null)
				return true;
			if (item != null && item.equals(arr[i]))
				return true;
		}

		return false;
	}
}
